//import {ToastMessager, MessagerLevel} from './messager.js'
import hljs from '../3rd/highlight.js/es/core.min.js';
import plaintext from '../3rd/highlight.js/es/languages/plaintext.min.js';
/*
import markdown from './highlight.js/es/languages/markdown.min.js';
hljs.registerLanguage('markdown', markdown);
*/

const _mapPromise = new Map();
hljs.registerLanguage('plaintext', plaintext);
_mapPromise.set('plaintext', Promise.resolve());
export function LoadLanguage(language) {
    let _p = _mapPromise.get(language);
    if(!_p) {
        _p = import(`/js/languages/${language}.min.js`)
            .then(module => {
                hljs.registerLanguage(language, module.default);
            }, err => {
                //ToastMessager.Show(`error loading language parser:\n${err}`, MessagerLevel.ERROR);
            }
            )
        _mapPromise.set(language, _p);
    }
    return _p;
}

/*
export function LanguageLoaded(lang) {
    return !!hljs.getLanguage(lang);
}
*/

export function Highlight(content, language) {
    return hljs.highlight(content, {language}).value;
}

